{extends file="../home.html"}

{block name="title"}{$head_title}{/block}
	
{block name="css"}
{/block}

{block name="content"}
<!--s主内容-->
<section class="content-wrapper">
  <div class="content-container container">
  	<!-- s面包屑导航 -->
  	{include file="../breadcrum_nav.html"}
  	<!-- e面包屑导航 -->
    <!-- s分类 -->
    <div class="col-left">
    {include file="../common_personal_nav.html"}
	</div>	
    <!-- e分类 -->
    <!-- s商品列表 -->
    <div class="col-main">
		{include file="../common_personal_header.html"}
		<!-- s主内容 -->
		<div class="user-main">
			<form action="" id="refund_form" name="refund_form" method="post">
			<h6 class="form-title">返修/退换货</h6>
			<table class="table table-striped table-bordered table-condensed">
				<thead>
					<tr>
						<ul class="nav nav-pills">
						  <li class="active">
						    <a href="{$refund_apply_link}{$order_info.order_id}">申请返修/退换货</a>
						  </li>
						  <li><a href="{$order_refund_detail_link}{$order_info.order_id}">查看返修/退换货记录</a></li>
						</ul>
					</tr>
				</thead>
			    <thead>
		          <tr>
		            <th>操作</th>
		            <th>商品编码</th>
		            <th>商品名称</th>
		            <th>数量</th>
		            <th>金额</th>
		            <th>下单时间</th>
		          </tr>
		        </thead>
		        <tbody>
				{foreach from=$item_list item=item}
		          <tr>
		            <td><input type="checkbox" name="item_check" data-item-id="{$item.item_id}" data-item-price="{$item.real_price}" data-item-number="{$item.number}"></td>
		            <td>{$item.item_sn}</td>
		            <td>{$item.item_name}</td>
		            <td><input class="daily_itemNum" name="number" type="text" onkeyup="write_number(this)" value="{$item.number}" data-item-number="{$item.number}"></td>
		            <td>{$item.real_price}</td>
		            <td>{$order_info.addtime|date_format:"%Y-%m-%d %H:%M:%S"}</td>
		          </tr>
		        {/foreach}		          
		        </tbody>
		      </table>
     		  <div class="center-btn"><a id="refund_apply" class="btn" href="javascript:;">申请退款</a></div>
     		  <input type="hidden" name="number_list" id="number_list">
			  <input type="hidden" name="item_id_list" id="item_id_list">
			  <input type="hidden" name="refund_price" id="refund_price">
			  <input type="hidden" name="act" value="refund">
     		  </form>

		</div>
		<!-- e主内容 -->

	</div>
	<div class="clearfix"></div>
    <!-- e商品列表 -->
  </div>
</section>
<!--e主内容-->
{/block}

{block name="js"}
<script>
{literal}
$(function(){
	//数量输入控制
	$('.daily_itemNum').blur(function(){
		var _this = $(this);
		if(!_this.val().match(/^\d+$/) && _this.val() != ""){
			alert('请输入正确的数量');
			return;
		}
		if(_this.val() > _this.data('item-number')){
			_this.val(_this.data('item-number'));
			alert('退货数量不能大于订单数量');			
			return;
		}
	});
	//申请退款
	$('#refund_apply').click(function(e){
		e.preventDefault();
		var number_list = '';
		var item_id_list = '';
		var refund_price = 0.00;
		$('input:checkbox[name="item_check"]:checked').each(function()
		{
			var _this = $(this);
			var num = _this.parent().parent().find('input[name=number]').val();
			var item_id = _this.data('item-id');
			var item_price = _this.data('item-price');
			number_list += num + ',';
			item_id_list += item_id + ',';
			refund_price += item_price * num;
		});

		number_list = number_list.substr(0, number_list.length - 1);
		item_id_list = item_id_list.substr(0, item_id_list.length - 1);

		if (!number_list)
		{
			alert('对不起，请至少选择一个商品！');
			return false;
		}
		$('#number_list').val(number_list);
		$('#item_id_list').val(item_id_list);
		$('#refund_price').val(refund_price);

		$('#refund_form').submit();
		//删除已申请退款的商品
		/*$('input:checkbox[name="item_check"]:checked').each(function()
		{
			var obj = $(this).parent().parent();
			obj.remove();
		});*/
	});
});
//控制输入不符
function write_number(t)
{
      t.value = t.value.replace(/[^\d]/g,'');
}
{/literal}
</script>
{/block}
